//
//  WSGoodsDetailSelectCell.m
//  FD
//
//  Created by Yasin on 2018/10/15.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//  外送 商品详情选择商品cell 选择cell
// cell 里面套一个collectionView



#import "WSGoodsDetailSelectCell.h"
#import "WSGoodsDetailSelectCollectionItem.h" //item
//350
@interface WSGoodsDetailSelectCell()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
/**父盒子*/
@property (nonatomic, strong) UIView *div1;
/**请选择 xxx lb*/
@property (nonatomic, strong) UILabel *selLb;
/**份数*/
@property (nonatomic, strong) UILabel *cntLb;
/**（已选xxxx)*/
@property (nonatomic, strong) UILabel *selectedLb;


/**clv*/
@property (nonatomic, strong) UICollectionView *clv;

@end

@implementation WSGoodsDetailSelectCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    //加一个边框
    self.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.layer.borderWidth = 1.0;
    
    [self.contentView addSubview:self.div1];
    [self.div1 addSubview:self.selLb];
    [self.div1 addSubview:self.cntLb];
    [self.div1 addSubview:self.selectedLb];
    
    [self.contentView addSubview:self.clv];
}

#pragma mark - 布局 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    [self.div1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.contentView);
        make.height.mas_equalTo(40);
    }];
    [self.selLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div1.mas_left).offset(10);
        make.centerY.equalTo(self.div1.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(100, 30));
    }];
    [self.cntLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.selLb.mas_right).offset(10);
        make.centerY.equalTo(self.div1.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    [self.selectedLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.cntLb.mas_right).offset(10);
        make.centerY.equalTo(self.div1.mas_centerY);
        make.height.mas_equalTo(30);
        make.right.equalTo(self.div1.mas_right).offset(10);
    }];
    
    [self.clv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.top.equalTo(self.div1.mas_bottom).offset(5);
        make.right.equalTo(self.div1.mas_right);
        make.height.mas_equalTo(300);
    }];
}


#pragma mark -getter
- (UIView *)div1 {
    if (!_div1) {
        _div1 = [UIView new];
//        _div1.backgroundColor = [UIColor lightGrayColor];
    }
    return _div1;
}

- (UILabel *)selLb {
    if (!_selLb) {
        _selLb = [UILabel new];
        _selLb.text = @"请选择商品";
        _selLb.font = [UIFont systemFontOfSize:13.0];
    }
    return _selLb;
}
- (UILabel *)cntLb {
    if (!_cntLb) {
        _cntLb = [UILabel  new];
        _cntLb.text = @"1";
        _cntLb.textColor = [UIColor redColor];
        _cntLb.font = [UIFont systemFontOfSize:13.0];
    }
    return _cntLb;
}
- (UILabel *)selectedLb {
    if (!_selectedLb) {
        _selectedLb = [UILabel new];
        _selectedLb.text = @"(已选这款减肥恐龙当家)";
        _selectedLb.font = [UIFont systemFontOfSize:13.0];
    }
    return _selectedLb;
}


- (UICollectionView *)clv {
    if (!_clv) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        
        _clv = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _clv.backgroundColor = [UIColor whiteColor];
        _clv.delegate = self;
        _clv.dataSource = self;
        
        //注册cell
        
        [_clv registerNib:[UINib nibWithNibName:@"WSGoodsDetailSelectCollectionItem" bundle:nil] forCellWithReuseIdentifier:@"WSGoodsDetailSelectCollectionItem"];
    }
    return _clv;
}

#pragma mark -clv代理2 UICollectionViewDelegate,
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    WSGoodsDetailSelectCollectionItem *item = [collectionView dequeueReusableCellWithReuseIdentifier:@"WSGoodsDetailSelectCollectionItem" forIndexPath:indexPath];
    
    return item;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CGFloat w = (SCREEN_WIDTH - 10*4) / 3;
    return CGSizeMake(w, w*1.2);
}


#pragma mark -clv代理3 UICollectionViewDataSource
#pragma mark -clv代理1 UICollectionViewDelegateFlowLayout

@end
